﻿/*******************************************************************************
 * Copyright © 2016 DJY 版权所有
 * Author: DJY
 * Description: 后台管理系统
 * Website：http://www.djyweb.cn
*********************************************************************************/

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace DJY.Code
{
    public class AjaxResult
    {
        public const string Success = "success";
        public const string Error = "error";

        /// <summary>
        /// 操作结果类型
        /// </summary>
        public string state { get; set; }
        /// <summary>
        /// 获取 消息内容
        /// </summary>
        public string message { get; set; }
        /// <summary>
        /// 获取 返回数据
        /// </summary>
        public object data { get; set; }

        /// <summary>
        /// 成功
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static AjaxResult OK(string msg, object data = null)
        {
            return new AjaxResult() { state = Success, message = msg, data = data };
        }

        /// <summary>
        /// 失败
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static AjaxResult Fail(string msg, object data = null)
        {
            return new AjaxResult() { state = Error, message = msg, data = data };
        }
    }
}
